package com.vanhon.engine.decrypt;

import android.util.Log;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import org.apache.http.HttpException;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.DefaultHttpResponseFactory;
import org.apache.http.impl.DefaultHttpServerConnection;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.BasicHttpProcessor;
import org.apache.http.protocol.HttpRequestHandlerRegistry;
import org.apache.http.protocol.HttpService;

/* loaded from: classes.dex */
public class DecryptServer {
    private static final int PORT = 36528;
    private static final String TAG = "DecryptServer";
    private static DecryptServer mInstance;
    private boolean mExiting;
    private Runnable mMainServerRunable = new Runnable() { // from class: com.vanhon.engine.decrypt.DecryptServer.1
        @Override // java.lang.Runnable
        public void run() {
            while (!DecryptServer.this.mExiting) {
                try {
                    final Socket accept = DecryptServer.this.mServerSocket.accept();
                    new Thread(new Runnable() { // from class: com.vanhon.engine.decrypt.DecryptServer.1.1
                        @Override // java.lang.Runnable
                        public void run() {
                            DecryptServer.this.handleConnection(accept);
                            try {
                                accept.close();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }).start();
                } catch (IOException e) {
                    e.printStackTrace();
                    return;
                }
            }
        }
    };
    private Thread mMainServerThread;
    private ServerSocket mServerSocket;
    private static Object mLock = new Object();
    private static boolean mInited = false;

    public int getPort() {
        return PORT;
    }

    private DecryptServer() {
        this.mExiting = false;
        mInited = false;
        this.mExiting = false;
        final Object obj = new Object();
        new Thread(new Runnable() { // from class: com.vanhon.engine.decrypt.DecryptServer.2
            @Override // java.lang.Runnable
            public void run() {
                try {
                    DecryptServer.this.mServerSocket = new ServerSocket(DecryptServer.PORT);
                    DecryptServer.this.mMainServerThread = new Thread(DecryptServer.this.mMainServerRunable);
                    DecryptServer.this.mMainServerThread.start();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                synchronized (obj) {
                    boolean unused = DecryptServer.mInited = true;
                    obj.notify();
                }
            }
        }).start();
        synchronized (obj) {
            while (!mInited) {
                try {
                    obj.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static DecryptServer getInstance() {
        DecryptServer decryptServer;
        synchronized (mLock) {
            if (mInstance == null) {
                mInstance = new DecryptServer();
            }
            decryptServer = mInstance;
        }
        return decryptServer;
    }

    public static boolean isEncrypted(byte[] bArr, int i) {
        return Decrypt.isEncrypted(bArr, i);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public int handleConnection(Socket socket) {
        HttpService httpService = new HttpService(new BasicHttpProcessor(), new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory());
        HttpRequestHandlerRegistry httpRequestHandlerRegistry = new HttpRequestHandlerRegistry();
        httpRequestHandlerRegistry.register("*", new MyHttpRequestHandler());
        httpService.setHandlerResolver(httpRequestHandlerRegistry);
        DefaultHttpServerConnection defaultHttpServerConnection = new DefaultHttpServerConnection();
        BasicHttpContext basicHttpContext = new BasicHttpContext();
        try {
            defaultHttpServerConnection.bind(socket, new BasicHttpParams());
            Log.e(TAG, "handleConnection==========================0");
            httpService.handleRequest(defaultHttpServerConnection, basicHttpContext);
            Log.e(TAG, "handleConnection==========================1");
            socket.close();
            Log.e(TAG, "handleConnection==========================2");
            defaultHttpServerConnection.shutdown();
            Log.e(TAG, "handleConnection==========================3");
            return 0;
        } catch (IOException e) {
            e.printStackTrace();
            return 0;
        } catch (HttpException e2) {
            e2.printStackTrace();
            return 0;
        }
    }
}
